package action.servlet;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import biz.UsersBiz;
import biz.impl.UsersBizImpl;
import entity.Users;


public class CheckRegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		
		UsersBiz ub = new UsersBizImpl();
		Users u =new Users(username,password,new Date(),1);
		
		if(ub.getUserByName(username)==null){
			ub.addUers(u);
			response.sendRedirect("login.jsp");
		}else{
			request.setAttribute("error", "用户名已被使用");
			request.getRequestDispatcher("register.jsp").forward(request, response);
		}
	}

}
